package com.lili.operate.controller;

import com.lili.common.result.Result;
import com.lili.model.operate.SearchHotWords;
import com.lili.operate.service.HotWordsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
@Api(tags = "热点服务")
public class HotWordsController {
    @Autowired
    HotWordsService hotWordsService;
    /**
     * 设置热词
     * @param searchHotWords
     * @return
     */
    @PostMapping("/save/hot/words")
    public Result saveHotWords(@RequestBody SearchHotWords searchHotWords){
        int rs = hotWordsService.saveHotWords(searchHotWords);
        return rs==1?Result.ok():Result.fail();
    }

    /**
     * 根据日期查询历史热词
     * @return
     */
    @GetMapping("/query/one/history")
    public Result queryHistoryWords(String time){
        List<SearchHotWords> list = hotWordsService.queryHistoryWords(time);
        return list==null?Result.fail():Result.ok(list);
    }

    /**
     * 根据日期查看近七天最受欢迎的热词
     * @param time
     * @return
     */
    @GetMapping("/query/many/history")
    public Result queryRecentlyWords(String time){
        List<SearchHotWords> list = hotWordsService.queryRecentlyWords(time);
        return list==null?Result.fail():Result.ok(list);
    }

    /**
     * 根据id删除热词
     * @param id
     * @return
     */
    public Result deleteWords(long id){
        int rs = hotWordsService.deleteWords(id);
        return rs==1?Result.ok():Result.fail();
    }

}
